linux 部署配置ntp server

您所在的位置:网站首页 linux ntp client linux 部署配置ntp server

linux 部署配置ntp server

2024-07-10 18:13| 来源: 网络整理| 查看: 265

部署配置ntp server 基本概念为什么要用NTPNTP的层次结构安装配置NTP公网ntp内网ntpclient 配置ntpq 的输出NTP配置文件(ntp.config)的一些说明ntpd、ntpdate的区别

基本概念 网络时间协议(NTP)用来同步网络上不同主机的系统时钟。所有受管理的主机可以与一台名为NTP服务器的指定时间服务器同步时间。另一方面,NTP服务器则与任何公共NTP服务器或者你所选择的任何服务器同步自己的时间。所有NTP管理的设备其系统时间同步时可以精确到毫秒级。 为什么要用NTP 由于制造方面的差异,所有(非原子)时钟并不完全以一样的速度运行。有些时钟往往走得快点,而有些时钟走得慢点。所以经过一段很长的时间后,一个时钟的时间与另一个时钟逐渐发生偏差,导致所谓的“时钟漂移”或“时间漂移”。为了尽量减小时钟漂移影响,使用NTP的主机应该定期与指定的NTP服务器进行联系,保持时钟同步。不同主机之间的时间同步对计划备份、入侵检测日志、分布式任务调度或事务簿记之类的事务而言很重要,甚至可能是监管合规所需要的一个要求。 NTP的层次结构 NTP时钟以分层层次结构来加以组织。该层次结构中的每一层被称为层(stratum)。层这个概念描述了某机器距离权威时间源有多少个NTP跳

在这里插入图片描述

Stratum 0含有几乎没有时间漂移的时钟,比如原子钟。这些时钟无法通过网络直接使用。Stratum N(N > 1)服务器对照Stratum N-1服务器同步其时间。Stratum N时钟可以通过网络彼此连接。 NTP最多可支持层次结构中的15层。Stratum 16被认为不同步、无法使用。 安装配置NTP 这里介绍2种方式(下面统一使用环境为ubuntu:18.04): 1.公网ntp server 服务,使用公网同步。 2.内网ntp server 服务,使用内网自建ntp同步。 公网ntp

安装

apt update apt install ntp ntpdate -y

修改配置 vim /etc/ntp.conf

# 记录系统时间与BIOS事件偏差的文件 driftfile /var/lib/ntp/ntp.drift # tzdata 提供的闰秒定义 leapfile /usr/share/zoneinfo/leap-seconds.list # log 记录 logfile /var/log/ntp.log statistics loopstats peerstats clockstats filegen loopstats file loopstats type day enable filegen peerstats file peerstats type day enable filegen clockstats file clockstats type day enable # 国内阿里云ntp server ntp.aliyun.com iburst minpoll 4 maxpoll 10 server ntp1.aliyun.com iburst minpoll 4 maxpoll 10 server ntp2.aliyun.com iburst minpoll 4 maxpoll 10 server ntp3.aliyun.com iburst minpoll 4 maxpoll 10 #国外apple(苹果)公司提供 server time2.apple.com iburst minpoll 4 maxpoll 10 server time3.apple.com iburst minpoll 4 maxpoll 10 server time4.apple.com iburst minpoll 4 maxpoll 10 server time5.apple.com iburst minpoll 4 maxpoll 10 # 访问控制限制 ## 拒绝用户服务器状态信息 restrict -4 default kod notrap nomodify nopeer noquery limited restrict -6 default kod notrap nomodify nopeer noquery limited ## 允许本地主机不受限制地访问 restrict 127.0.0.1 restrict ::1 ## 允许192.168.50.0/24网段内的服务器受限制请求同步服务器 restrict 192.168.50.0 mask 255.255.255.0 nomodify notrap nopeer noquery #忽略所有端口之上的监听,监听指定IP interface ignore wildcard interface listen 127.0.0.1 interface listen 192.168.50.235

启动服务&测试

ntpdate -u ntp.aliyun.com systemctl start ntp systemctl enable ntp #查看与上层ntp服务器的状态 ntp -p

在这里插入图片描述

内网ntp

安装

apt update apt install ntp ntpdate -y

修改配置 vim /etc/ntp.conf

# 记录系统时间与BIOS事件偏差的文件 driftfile /var/lib/ntp/ntp.drift # log 记录 logfile /var/log/ntp.log # 公共的NTP服务地址,因为该服务仅在内网使用,且该主机为服务器,所以配置本机地址 server 127.127.1.0 #NTP使用伪IP地址127.127.8.n 访问安装在本地计算机上的Meinberg无线电时钟。为了访问自己的系统时钟,也称为本地时钟,NTP使用伪IP地址127.127.1.0。 #此IP地址不得与127.0.0.1混淆,后者是本地主机的IP ,即计算机的环回接口。 #stratum 层次 根据上层server的层次而设定 作为局域网的time service provider,通常将stratum设置为10 fudge 127.127.1.0 stratum 10 ## 拒绝用户获取服务器状态信息 restrict -4 default kod notrap nomodify nopeer noquery limited restrict -6 default kod notrap nomodify nopeer noquery limited ## 允许本地主机不受限制地访问 restrict 127.0.0.1 restrict ::1 ## 允许192.168.50.0/24网段内的服务器受限制请求同步服务器 restrict 192.168.50.0 mask 255.255.255.0 nomodify notrap nopeer noquery #忽略所有端口之上的监听,监听指定IP interface ignore wildcard interface listen 127.0.0.1 interface listen 192.168.50.235

启动&查看状态

systemctl start ntp systemctl enable ntp systemctl status ntp

在这里插入图片描述

ntpq查看

在这里插入图片描述

client 配置

准备hosts

cat >> /etc/hosts


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3